@model UrlRecordSearchModel

@{
    //page title
    ViewBag.PageTitle = T("Admin.System.SeNames").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Search engine friendly names");
}

@{
    const string hideSearchBlockAttributeName = "UrlRecordPage.HideSearchBlock";
    var hideSearchBlock = genericAttributeService.GetAttribute<bool>(workContext.CurrentCustomer, hideSearchBlockAttributeName);
}

<div class="content-header clearfix">
    <h1 class="pull-left">
        @T("Admin.System.SeNames")
    </h1>
    <div class="pull-right">
        <button type="button" id="delete-selected" class="btn bg-red">
            <i class="fa fa-trash-o"></i>
            @T("Admin.System.SeNames.DeleteSelected")
        </button>
        <nop-action-confirmation asp-button-id="delete-selected" />
        @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.SenamesButtons })
    </div>
</div>

<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.SenamesTop })
            <div class="panel panel-default panel-search">
                <div class="panel-body">
                    <div class="row search-row @(!hideSearchBlock ? "opened" : "")" data-hideAttribute="@hideSearchBlockAttributeName">
                        <div class="search-text">@T("Admin.Common.Search")</div>
                        <div class="icon-search"><i class="fa fa-search" aria-hidden="true"></i></div>
                        <div class="icon-collapse"><i class="fa fa-angle-down" aria-hidden="true"></i></div>
                    </div>

                    <div class="search-body @(hideSearchBlock ? "closed" : "")">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <div class="col-md-4">
                                        <nop-label asp-for="SeName" />
                                    </div>
                                    <div class="col-md-8">
                                        <nop-editor asp-for="SeName" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-4">
                                        <nop-label asp-for="LanguageId" />
                                    </div>
                                    <div class="col-md-8">
                                        <nop-select asp-for="LanguageId" asp-items="Model.AvailableLanguages" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-4">
                                        <nop-label asp-for="IsActiveId" />
                                    </div>
                                    <div class="col-md-8">
                                        <nop-select asp-for="IsActiveId" asp-items="Model.AvailableActiveOptions" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-8 col-md-offset-4">
                                        <button type="button" id="search-senames" class="btn btn-primary btn-search"><i class="fa fa-search"></i>@T("Admin.Common.Search")</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-body">
                    @await Html.PartialAsync("Table", new DataTablesModel
                    {
                        Name = "sename-grid",
                        UrlRead = new DataUrl("SeNames", "Common", null),
                        SearchButtonId = "search-senames",
                        Length = Model.PageSize,
                        LengthMenu = Model.AvailablePageSizes,
                        Filters = new List<FilterParameter>
                        {
                            new FilterParameter(nameof(Model.SeName)),
                            new FilterParameter(nameof(Model.LanguageId)),
                            new FilterParameter(nameof(Model.IsActiveId))
                        },
                        ColumnCollection = new List<ColumnProperty>
                        {
                            new ColumnProperty(nameof(UrlRecordModel.Id))
                            {
                                IsMasterCheckBox = true,
                                Render = new RenderCheckBox("checkbox_senames"),
                                ClassName = NopColumnClassDefaults.CenterAll,
                                Width = "50"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.Id))
                            {
                                Title = T("Admin.System.SeNames.Id").Text,
                                ClassName = NopColumnClassDefaults.CenterAll,
                                Width = "50"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.Name))
                            {
                                Title = T("Admin.System.SeNames.Name").Text
                            },
                            new ColumnProperty(nameof(UrlRecordModel.EntityId))
                            {
                                Title = T("Admin.System.SeNames.EntityId").Text,
                                Width = "80"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.EntityName))
                            {
                                Title = T("Admin.System.SeNames.EntityName").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.IsActive))
                            {
                                Title = T("Admin.System.SeNames.IsActive").Text,
                                Width = "80",
                                ClassName = NopColumnClassDefaults.CenterAll,
                                Render = new RenderBoolean()
                            },
                            new ColumnProperty(nameof(UrlRecordModel.Language))
                            {
                                Title = T("Admin.System.SeNames.Language").Text,
                                Width = "100"
                            },
                            new ColumnProperty(nameof(UrlRecordModel.DetailsUrl))
                            {
                                Title = T("Admin.System.SeNames.Details").Text,
                                Width = "100",
                                ClassName = NopColumnClassDefaults.Button,
                                Render = new RenderCustom("renderColumnDetailsUrl")
                            }
                        }
                    })
                </div>
            </div>
            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.SenamesBottom })
        </div>
    </div>
</div>
<script>
    function renderColumnDetailsUrl(data, type, row, meta) {
        if (row.DetailsUrl && row.DetailsUrl.length > 0) {
            return '<a class="btn btn-default" href="' + row.DetailsUrl + '"><i class="fa fa-pencil"></i>@T("Admin.System.SeNames.Details")</a>';
        }
        else {
            return '';
        }
    }
</script>
<script>
    $(document).ready(function() {
        //"delete selected" button
        $("#delete-selected-action-confirmation-submit-button").bind("click", function () {
            var postData = {
                selectedIds: selectedIds
            };
            addAntiForgeryToken(postData);
            $.ajax({
                cache: false,
                type: "POST",
                url: "@(Url.Action("DeleteSelectedSeNames", "Common"))",
                data: postData,
                traditional: true,
                error: function (jqXHR, textStatus, errorThrown) {
                    $('#deleteSelectedSeNamesFailed-info').text(errorThrown);
                    $("#deleteSelectedSeNamesFailed").click();
                },
                complete: function (jqXHR, textStatus) {
                    updateTable('#sename-grid');
                }
            });
            $('#delete-selected-action-confirmation').modal('toggle');
            return false;
        });
    });
</script>
<nop-alert asp-alert-id="deleteSelectedSeNamesFailed" />